package mt.comm;

import java.io.Serializable;

import mt.Order;

/**
 * Messages sent from clients to the server. A message contains a type (enum), the nickname of the sender (String), 
 * and, depending on the message type, a new order. 
 * 
 * @author Nuno Santos
 *
 */
public class ServerSide implements ServerSideMessage, Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 23452;
	private String senderNickname;
	private Type type;
	private Order order = null;
	
	public ServerSide(Type type, String senderNickname, Order order){
		if(type == null || senderNickname == null)
			throw new IllegalArgumentException("The type and the sendersNickame can't be null.");
		
		this.type = type;
		
		if(type.equals(Type.NEW_ORDER));
			this.order = order;
			
		this.senderNickname = senderNickname;
	}
	
	/**
	 * Gets the type of the message.
	 * 
	 * @return type of the message.
	 */
	
	@Override
	public Type getType() {
		return type;
	}

	/**
	 * Gets the sender nickname.
	 * 
	 * @return sender's nickname.
	 */
	@Override
	public String getSenderNickname() {
		return senderNickname;
	}

	/**
	 * Gets the order in the message.
	 * 
	 * @return order.
	 */
	
	@Override
	public Order getOrder() {
		return order;
	}

}
